package com.link2room.optimus.controller.manager;

import com.link2room.common.constant.BaseConstant;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.optimus.dto.param.manager.PricePoolManagerParamDto;
import com.link2room.optimus.dto.result.base.PricePoolDto;
import com.link2room.optimus.facade.IPricePoolFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.optimus.constant.PermissionConstant.*;

/**
 * Created by sss on 2016/8/29.
 */
@Api(tags = "价格池管理")
@RestController
@RequestMapping("/manager/PricePools")
public class PricePoolManagerController {
    @Resource
    private IPricePoolFacadeService pricePoolFacadeService;

    @ApiOperation(value = "获取价格池列表",response = PricePoolDto.class)
    @RequestMapping(method = RequestMethod.GET)
    @L2RPermissionResources(value = pricePools, name = "价格池列表")
    public BaseResultDto pricePools() throws Exception {
        PricePoolManagerParamDto pricePoolManagerParamDto =new PricePoolManagerParamDto();
        QueryResult<PricePoolDto> pricePoolDtoResult = pricePoolFacadeService.listPricePools(pricePoolManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(pricePoolDtoResult);
        return l2rRs;
    }

    @ApiOperation(value = "根据ID获取价格池",response = PricePoolDto.class)
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @L2RPermissionResources(value = pricePool, name = "价格池详情")
    public BaseResultDto pricePool(
            @PathVariable Long id
    ) throws Exception {
        PricePoolManagerParamDto pricePoolManagerParamDto =new PricePoolManagerParamDto();
        pricePoolManagerParamDto.setId(id);
        PricePoolDto pricePoolDto = pricePoolFacadeService.getPricePool(pricePoolManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(pricePoolDto);
        return l2rRs;
    }

    @ApiOperation(value = "保存价格池")
    @RequestMapping(method = RequestMethod.POST)
    @L2RPermissionResources(value = newPricePool, name = "新建价格池")
    public BaseResultDto newPricePools(
            @RequestBody PricePoolManagerParamDto pricePoolManagerParamDto
    ) throws Exception {
        pricePoolFacadeService.savePricePool(pricePoolManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "更新价格池")
    @RequestMapping(method = RequestMethod.PUT)
    @L2RPermissionResources(value = basePriceStaticsModify, name = "更新价格池")
    public BaseResultDto basePriceStaticsModify(
            @RequestBody PricePoolManagerParamDto pricePoolManagerParamDto
    ) throws Exception {
        pricePoolFacadeService.updatePricePool(pricePoolManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.UPDATESUCCESS);
        return l2rRs;
    }
}
